@extends('layouts.default')

@section('title')
设备返修
@stop

@section('pre')
<li class="active"><span>@yield('title')</span></li>
@stop

@section('css')
<style type="text/css">
    .phone-group{
        height:30px;
    }
</style>
@stop

@section('content')

<div class="row">
    <div class="col-md-12">
        <div class="main-box">
            <header class="main-box-header clearfix">
                <h2>返修详情</h2>
            </header>
            <div class="main-box-body clearfix">
                <form role="form" method="post" onsubmit="return check()">
                    <div class="form-group col-md-12">
                        <label for="logistics" class="control-label col-md-2">物流</label>
                        <div class="col-md-10">
                            <input class="form-control" name="logistics" id="logistics" type="text" placeholder="请输入物流类型" value="{{isset($data['logistics'])?$data['logistics']:''}}" required="required"/>
                        </div>
                    </div>
                    <div class="form-group col-md-12">
                        <label for="num" class="control-label col-md-2">物流单号</label>
                        <div class="col-md-10">
                            <input class="form-control" name="logistics_order" id="logistics_order" type="text" placeholder="请输入物流单号" value="{{isset($data['logistics_order'])?$data['logistics_order']:''}}" required="required"/>
                        </div>
                    </div>
                    <div class="form-group col-md-12">
                        <label for="fee" class="control-label col-md-2">物流费用</label>
                        <div class="col-md-10">
                            <input class="form-control" name="pay" id="pay" type="text" placeholder="请输入物流费用" onkeyup="this.value = this.value.replace(/\D/g, '')" onafterpaste="this.value=this.value.replace(/\D/g,'')" value="{{isset($data['pay'])?$data['pay']:''}}"/>
                        </div>
                    </div>
                    <div class="form-group col-md-12">
                        <label for="content" class="control-label col-md-2">返修详情</label>
                        <div class="col-md-10">
                            <textarea name="content" id="content" style="width:100%;height: 200px;">{{isset($data['content'])?$data['content']:''}}</textarea>
                        </div>
                    </div>
                    <div class="form-group col-md-12">
                        <label for="devices" class="control-label col-md-2">设备列表</label>
                        <div class="col-md-10">
                            <table class="table" id="devices">
                                <th>设备ID</th><th>硬件系列号</th><th>通讯系列号</th><th>操作</th>
                            </table>
                        </div>
                    </div>
                    <div class="form-group col-md-12">
                        <label for="num" class="control-label col-md-2"></label>
                        <div class="col-md-10">
                            <button type="submit" class="btn btn-primary">提交</button>
                        </div>
                    </div>
                </form>
                <div class="box box-success">
                    <div class="box-header" style="cursor: move;">
                        <h3 class="box-title">
                            <i class="fa fa-plus"></i>
                            添加设备
                        </h3>

                        <div class="box-tools pull-right">

                        </div>
                    </div>
                    <!-- /.box-header -->
                    <div class="box-body">
                        <div class="box-body">
                            <!-- General tab -->
                            <div class="tab-pane active" id="tab-general">
                                <!-- CSRF Token -->
                                <input type="hidden" name="_token" value="{{{ csrf_token() }}}" />
                                <!-- ./ csrf token -->
                                <!-- id -->
                                <div class="form-group {{{ $errors->has('id') ? 'has-error' : '' }}}">
                                    <label class="span2 control-label" style="color: #ff0000">*</label>
                                    <label class="span2 control-label" for="id">设备ID</label>
                                    <label class="length-tip control-label" data-limit="50" for="id"></label>
                                    <div class="span6">
                                        <input class="form-control" type="text" name="id" id="id" value="{{{ Input::old('id', '') }}}" onkeyup="this.value = this.value.replace(/\D/g, '')" onafterpaste="this.value=this.value.replace(/\D/g,'')"/>
                                    </div>
                                </div>
                                <!-- ./ id -->
                                <!-- hardware_serial -->
                                <div class="form-group {{{ $errors->has('hardware_serial') ? 'has-error' : '' }}}">
                                    <label class="span2 control-label" style="color: #ff0000">*</label>
                                    <label class="span2 control-label" for="hardware_serial">硬件系列号</label>
                                    <label class="length-tip control-label" data-limit="50" for="hardware_serial"></label>
                                    <div class="span6">
                                        <input class="form-control" type="text" name="hardware_serial" id="hardware_serial" value="{{{ Input::old('hardware_serial', '') }}}" />
                                    </div>
                                </div>
                                <!-- ./ hardware_serial -->

                                <!-- communication_serial -->
                                <div class="form-group {{{ $errors->has('communication_serial') ? 'has-error' : '' }}}">
                                    <label class="span2 control-label" style="color: #ff0000">*</label>
                                    <label class="span2 control-label" for="communication_serial">通讯系列号</label>
                                    <label class="length-tip control-label" data-limit="50" for="hardware_serial"></label>
                                    <div class="span6">
                                        <input class="form-control" type="text" name="communication_serial" id="communication_serial" value="{{{ Input::old('communication_serial', '') }}}" />
                                    </div>
                                </div>
                                <!-- ./ hardware_serial -->
                            </div>
                            <!-- ./ general tab -->

                            <!-- Form Actions -->
                            <div class="form-group">
                                <div class="span6 offset2">
                                    <button type="button" class="btn btn-success info-search" style="margin-left: 20px" onclick="search()"> 搜索</button>
                                </div>
                            </div>
                            <!-- ./ form actions -->
                        </div>
                        <ul class="todo-list ui-sortable">

                        </ul>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
@stop

@section('js')
<script type="text/javascript">
    function search() {
        $.ajax({
            type: "get",
            async: false,
            url: "{{ URL::to('repairsearch') }}",
            data: {
                id: $("#id").val(),
                hardware_serial: $("#hardware_serial").val(),
                communication_serial: $("#communication_serial").val()
            },
            dataType: "json",
            cache: false,
            success: function (data) {
                if (data == 0) {
                    $(".todo-list.ui-sortable").html("没有搜索结果");
                } else {
                    var html = '<table class="table table-hover search-list"><tr><th class="col-md-1">设备ID</th><th class="col-md-1">硬件系列号</th><th class="col-md-1">通讯系列号</th><th class="col-md-2">操作</th></tr>';
                    for (var i = 0; i < data.length; i++) {
                        html += '<tr id="d_' + data[i].id + '"><td>' + data[i].id + '<input type="hidden" value="'+data[i].id+'" name="ids[]"/></td><td>' + data[i].hardware_serial + '</td><td>' + data[i].communication_serial + '</td>';
                        if(typeof($("#l_"+data[i].id).html())== 'undefined'){
                            html+='<th><a href="javascript:;" class="btn btn-success" onclick="addList(' + data[i].id + ')">加入列表</a></th></tr>';
                        }else{
                            html+='<th>已添加</tr>';
                        }
                    }
                    html += '</table>';
                    $(".todo-list.ui-sortable").html(html);
                }
            }
        });
    }
    function addList(id) {
        var html = '<tr id="l_'+id+'">';
        html += $("#d_" + id).html();
        html+='<td><a class="btn btn-warning" onclick="removeMsg('+id+')">移除</a><td>';
        html+='</tr>';
        $("#d_" + id + " th").html("已添加");
        $("#devices").append(html);
        $("#l_" + id + " th").remove();
    }
    function removeMsg(id){
        $("#l_" + id).remove();
        $("#d_" + id + " th").html('<a href="javascript:;" class="btn btn-success" onclick="addList(' + id + ')">加入列表</a></th>');
    }
    function check(){
        //alert($("#devices td")).html();
        //return false;
    }
</script>
@stop

